/**
 * 给定一个整数数组 nums，将数组中的元素向右轮转 k 个位置，其中 k 是非负数。

 

示例 1:

输入: nums = [1,2,3,4,5,6,7], k = 3
输出: [5,6,7,1,2,3,4]
解释:
向右轮转 1 步: [7,1,2,3,4,5,6]
向右轮转 2 步: [6,7,1,2,3,4,5]
向右轮转 3 步: [5,6,7,1,2,3,4]
示例 2:

输入：nums = [-1,-100,3,99], k = 2
输出：[3,99,-1,-100]
解释: 
向右轮转 1 步: [99,-1,-100,3]
向右轮转 2 步: [3,99,-1,-100]
 

提示：

1 <= nums.length <= 105
-231 <= nums[i] <= 231 - 1
0 <= k <= 105
 




 */
export class LeetCode189 {
    rotate(nums: number[], k: number): void {
        let len = nums.length;
        let mod = len % k;
        let totalMoveTime = 0;
        let orgIndex = 0;
        let startIndex = 0;
        let temp = nums[startIndex];
        let targetIndex;
        let vTarget;
        for (let index = 0; index < len; index++) {
            targetIndex = (startIndex + k) % len;
            vTarget = nums[targetIndex];
            nums[targetIndex] = temp;
            totalMoveTime++;

            temp = vTarget;
            startIndex = targetIndex;
            if (targetIndex == orgIndex) {
                orgIndex++;
                startIndex = orgIndex;
                temp = nums[startIndex];
            }
        }

    };

    start() {
        let nums = [1, 2, 3, 4, 5, 6];
        let k = 4;
        this.rotate(nums, k);
        for (let index = 0, len = nums.length; index < len; index++) {
            let ele = nums[index];
            console.log("nums: ", index, ele);
        }

    }
}